package com.app.TCES.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.app.TCES.domain.Class;
import com.app.TCES.domain.Department;
import com.app.TCES.domain.Student;
import com.app.TCES.domain.Student_Dept_Class;
import com.app.TCES.mapper.A_studentMapper;

@Service
public class A_studentService {

	Logger log = LogManager.getLogger(A_studentService.class);

	@Autowired
	A_studentMapper a_studentMapper;

	// 学生信息
	public List<Student_Dept_Class> selectStudents(Integer tmp,Integer limit) {
		log.debug("--->adminSevice  selectStudents");
		List<Student_Dept_Class> students = a_studentMapper.SelectStudents(tmp,limit);
		log.debug("adminSevice  selectStudents  --->");
		return students;
	}
	//查询所有学生条数(分页)
	public int total() {
		int a = a_studentMapper.total();
		return a;
	}
	
	//查询院系
	public List<Department> selecDepartments(){
		List<Department> departments = a_studentMapper.selectdept();
		return departments;
	}
	
	//通过院系(Name)查班级
	public List<Class> selcetClasses(String deptName){
		log.debug("--->adminSevice  selectClasses");
		List<Class> classes = a_studentMapper.selectClasses(deptName);
		log.debug("adminSevice  selectClasses--->");
		return classes;
	}
	
	//通过院系(Name)查学生条数(分页)
	public int total1(String deptName) {
		int a = a_studentMapper.total1(deptName);
		return a;
	}
	
	//通过院系(Name)查班级
		public List<Class> selcetC(int deptId){
			log.debug("--->adminSevice  selectClasses");
			List<Class> c = a_studentMapper.selectC(deptId);
			log.debug("adminSevice  selectClasses--->");
			return c;
		}
	
	//点击学院按钮(Name)查学生
	public List<Student_Dept_Class> selectDept_Student(Integer tmp,Integer limit,String deptName){
		List<Student_Dept_Class> list = a_studentMapper.selectDept_Student(tmp,limit,deptName);
		return list;
	}
	
	//通过班级(Name)查询学生条数(分页)
	public int total2(String className) {
		int a = a_studentMapper.total2(className);
		return a;
	}
	
	//点击班级按钮查询学生
	public List<Student_Dept_Class> selectClass_Studnet(Integer tmp,Integer limit,String className){
		List<Student_Dept_Class> list = a_studentMapper.selectClass_Studnet(tmp,limit,className);
		return list;
	}
	//
	
	//更新学生信息
	public void updateStudent(int stuId,int deptId,int classId) {
		a_studentMapper.updateStudent(deptId, classId, stuId);
	}
	
	//删除
	public void delStudent(int stuId) {
		log.debug("========执行删除");
		a_studentMapper.delStudent(stuId);
	}
	
	//添加学生
	public String  insertStudent(int stuId,String stuName,int deptId,int classId) {
		//验证stuId是否重复
		log.debug("验证stuId是否重复");
		List<Student>  a = new ArrayList<Student>();
		a=a_studentMapper.validation_StuId(stuId);
		
		if(a.isEmpty()) {
			log.debug("添加学生信息");
			String password = "123456";
			a_studentMapper.insertStudent(stuId, stuName, password, deptId, classId);
			return "YES";
			
		}else {
			log.debug("stuId重复");
			return "NO";
		}
		
	}
	
	//模糊查询
	public List<Student_Dept_Class> FQ(Integer tmp,Integer limit,String msg,String deptName,String className){
		
		if(deptName.equals("全部院系") == true) {
			log.debug("开始模糊查询");
			log.debug("1");
			List<Student_Dept_Class> list = a_studentMapper.FQ1(tmp, limit, msg);
			return list;
		}else if(deptName.equals("全部院系") == false || className.equals("全部班级")== true){
			log.debug("2");
			List<Student_Dept_Class> list = a_studentMapper.FQ2(tmp, limit, msg, deptName);
			return list;
		}else{
			log.debug("开始模糊查询");
			log.debug("3");
			List<Student_Dept_Class> list = a_studentMapper.FQ3(tmp,limit,msg,deptName,className);
			return list;
		}
		
		
	}
	
	//模糊查询条数
	public int total3(String msg,String deptName,String className) {
		if(deptName.equals("全部院系") == true) {
			log.debug("1");
			int a =a_studentMapper.total3(msg);
			return a;
		}else if(deptName.equals("全部院系") == false || className.equals("全部班级")== true){
			log.debug("2");
			int a = a_studentMapper.total4(msg, deptName);
			return a;
		}else {
			log.debug("3");
			int a = a_studentMapper.total5(msg,deptName,className);
			return a;
		}	
	}
	
	//重置密码
	public String updatePassword(int stuId){
		String password = "123456";
		a_studentMapper.RP(password, stuId);
		return "YES";
	}
}
